local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, CommonOHOH.files.BaseObject(),"car_base");
local ConnectClass=_G.CommonOHOH.load.Connect();
local CarTool=	_G.CommonOHOH.load.CarTool()

-- 车的部件基类
function M.new(...)
	return M(...);
end;

function M.ctor(self,car)--构造函数
    self.Car=car --整车对象
	M.super.ctor(self);
end;

--更新部件
function M.Update(self,carId)

    self.CarId=carId --改部件的Id
    self:DestroyInstance()
    self:CreateInstance()
    self:Assemble()
end

--创建实例
function M.CreateInstance(self)
    self.Model=CarTool.CreatePartModel(self.CarId) --获取部件模型
    
    for _,p in pairs(self.Model:GetDescendants()) do
        if p:IsA("BasePart") then
            p.Massless = true
            p.Anchored = false
            p.CanQuery = false
            p.CanCollide = false
            p.CanTouch = false
        end
    end
    self.Instance = self.Model.Instance
--model大小，用于碰撞盒生成
    local boundingCFrame, boundingSize =self.Model:GetBoundingBox()
    boundingSize = Vector3.new(boundingSize.X,4,boundingSize.Z)
    self.BoundingSize = boundingSize
end

-- 销毁实例
function M.DestroyInstance(self)

    if  self.Instance then -- 销毁旧的对象
        self.Instance:Destroy()
        self.Instance=nil
    end

    if  self.Model then -- 销毁旧的对象
        self.Model:Destroy()
        self.Model=nil
    end
end


--添加约束
function M.Weld2Part(self,a,b)
    local weld = Instance.new("WeldConstraint")
	weld.Part0 = a
	weld.Part1 = b
	weld.Parent = a
end

-- 获取组装到车上的实例
function M.GetInstance(self)
    return self.Instance
end



function M.Assemble(self)
-------.........

end



function M.dtor(self)
    self:DestroyInstance()
	M.super.dtor(self);
end;



return M